import { Module, ExistingProvider } from "@nestjs/common";
import { SharedModule } from "./shared/shared.module";
import { ConfigModule } from "@nestjs/config";
import configuration from "./config/configuration";
import { AuthModule } from "./modules/system/auth/auth.module";
import { LoginModule } from "./modules/login/login.module";
import { DeptModule } from "./modules/system/dept/dept.module";
import { MenuModule } from "./modules/system/menu/menu.module";
import { RoleModule } from "./modules/system/role/role.module";
import { UserModule } from "./modules/system/user/user.module";
import { LogModule } from "./modules/monitor/log/log.module";
import { TestTableModule } from "./modules/system/testTable/testTable.module";
import { CommonModule } from "./modules/common/common.module";

/* 将 provider的类名作为别名，方便定时器调用 */
const providers = [];
function createAliasProviders(): ExistingProvider[] {
  const aliasProviders: ExistingProvider[] = [];
  for (const p of providers) {
    aliasProviders.push({
      provide: p.name,
      useExisting: p,
    });
  }
  return aliasProviders;
}
const aliasProviders = createAliasProviders();

@Module({
  imports: [
    // 配置文件模块
    ConfigModule.forRoot({
      isGlobal: true,
      load: [configuration],
    }),
    // 公共模块
    SharedModule,

    // 业务模块
    LoginModule,
    AuthModule,
    DeptModule,
    MenuModule,
    RoleModule,
    UserModule,
    LogModule,
    CommonModule,

    // 示例模块
    TestTableModule,
  ],
  providers: [...aliasProviders],
})
export class AppModule {}
